/**
 * 系统后台脚本服务JS-dataServices.jsp
 */

// 项目路径
var strPath = window.document.location.pathname;
//var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);
var postPath = "/gdp";
var guid = "";
var biaobiao = "";

var dbk = "";
var ppid = 10000;

var x = "";
var a = "";
var b = "";
var c = "";
var d = ""
var e = "";
var f = "";
var g = "";
var h = "";

var attrs = 0;

var add = "";

var syslist = new Array();

//参数0
$("#hid_servertype").val(GetQueryString("servertype"));//服务类型 添加使用
$("#hid_operate").val(GetQueryString("operate")); //操作类型
$("#hid_serviceId").val(GetQueryString("servercode"));//服务ID  修改使用
$("#hid_projectid").val(GetQueryString("projectid"));//工程ID 添加修改预留
$('#btn_serverSave').show();
var iso = "";
var sts = "";
$(document).ready(function () {
    $("#sqlsql").hide();
    $("#sqlssqls").hide();
    //默认生成服务ID
    $("#serverId").val(GetQueryString("projectid") + "_" + "executeSqlServer_" + randomWord(false, 4, 4));

    function randomWord(randomFlag, min, max) {
        var str = "",
            range = min,
            arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];

        // 随机产生
        if (randomFlag) {
            range = Math.round(Math.random() * (max - min)) + min;
        }
        for (var i = 0; i < range; i++) {
            pos = Math.round(Math.random() * (arr.length - 1));
            str += arr[pos];
        }
        return str;
    }

    function showDbkey() {
        $.ajax({
            type: 'get',
            // url: postPath + '/system/treeConfig/getTreeList',
            url: postPath + '/system/sysProject/getProjectToDataSource?pcode=' + GetQueryString("projectid"),
            async: false,
            success: function (res) {
                $("#dbkey").append('');
                var strtxt = "<option value=''>请选择</option>";
                if (res.success) {
                    $.each(res.data, function (i, e) {
                        strtxt += "<option value='" + e.dbKey + "'>" + e.dbMark + "(" + e.dbKey + ")" + "</option>";
                    });
                }
                $("#dbkey").html(strtxt);
            },
            error: function () {
                alert('error...');
            }
        });
    }

    showDbkey();
    attrs = 1;
    // 左侧tree数据绑定
    var setting = {
        data: {
            key: {
                title: "hint"
            },
            simpleData: {
                enable: true
            }
        },
        callback: {
            onClick: onClick
        }
    };
    var zNodes = GetLeftTreeData();
    $.fn.zTree.init($("#tree"), setting, zNodes);

    //判断服务修改还是添加
    if ($("#hid_operate").val() == "edit") {
        iso = $("#hid_serviceId").val();
        $("#serverId").attr("readonly", "readonly");
        attrs = 2;
        GetServerListselect();
        $("#tab_1_1_5").hide();
        $("#tab_1_1_2").hide();
        $("#tab_1_1_1").show();
        $("#tab_1_1_3").hide();
    }

    // 左侧树刷新操作
    $("#tree_refresh").click(function () {
        zNodes = GetLeftTreeData();
        $.fn.zTree.init($("#tree"), setting, zNodes);
    });

//					//定位到表信息配置选项卡
    function locationTab() {
        $('#myTab a[href="#tab_1_1_1"]').tab('show');
    }

    function locationcolumn() {
        $('#myTab a[href="#tab_2_1"]').tab('show');
    }

    $("#a_fieldconfig_2_2").click(function () {
        locationcolumn();
        $("#tab_2_1").hide();
        $("#tab_2_2").show();

    });
    $("#a_fieldconfig_2_1").click(function () {
        cleanColumn();
        locationcolumn();
        $("#tab_2_2").hide();
        $("#tab_2_1").show();
        myCodeMirrorColumn.setValue(myCodeMirror.getValue().sqlreplaceAll(";", " "));

    });

    // Tree点击事件
    function onClick(event, treeId, treeNode, clickFlag) {
        //locationTab();
        biaobiao = treeNode.id;
        ppid = treeNode.pid;
        dbk = treeNode.id;
        showTableName();
        validateDataing();
        locationTab();
        if (ppid == 0) {
            //$("#dbKey").val("DB_rmsdb");
            $("#dbkey").val(treeNode.id);
            attrs = 1;
            $("#serverId").attr("readonly", false);
            $("#tab_1_1_5").hide();
            $("#tab_1_1_2").hide();
            $("#tab_1_1_1").show();
            $("#tab_1_1_3").hide();
            //getListser();
        } else {
            $("#dbkey").val(treeNode.pid);
            $("#serverId").attr("readonly", "readonly");
            attrs = 2;
            GetServerList();
            $("#tab_1_1_5").hide();
            $("#tab_1_1_2").hide();
            $("#tab_1_1_1").show();
            $("#tab_1_1_3").hide();
        }
    }

    // 获取详情
    $("#btn_Search").click(function () {
        $("#dbKey").val(biaobiao);
        attrs = 1;
        $("#serverId").attr("readonly", false);
        $("#tab_1_1_5").hide();
        $("#tab_1_1_2").hide();
        $("#tab_1_1_1").hide();
        //$("#tab_1_1_4").show();
        //getListser();
    });
    // 添加节点操作
    $("#addjie").click(function () {
        cleanContent();
        if (ppid != 0) {
            showMsg("请选择父节点!", "warning");
            // bootbox.alert("请选择父节点!");
            return;
        }
        $("#serverids").show();
        $("#dbkeys").val(biaobiao);
        $("#dbkeys").attr("readonly", "readonly");
        $("#EditContent").modal('show');
        editStart = 1;
    });

    // 修改操作
    $("#btn_edit")
        .click(
            function () {
                cleanContent();
                if (ppid == 0) {
                    // bootbox.alert("请选择需要修改的节点!");
                    showMsg("请选择需要修改的节点!", "warning");
                    return;
                }
                guid = biaobiao;
                // console.log("修改")
                $
                    .ajax({
                        type: 'get',
                        url: postPath
                            + '/system/server/seleServerOne',
                        async: false,
                        data: {
                            key: guid
                        },
                        success: function (res) {
                            $("#guid").val(guid);
                            $("#guid").attr(
                                "readonly",
                                "readonly");
                            $("#name")
                                .val(res.name);
                            $("#dbkey").val(
                                res.dbkey);
                            $("#sql").val(res.sql);
                            $("#remark").val(
                                res.remake);
                            if (res.catched == 1) {
                                $("#male").attr(
                                    'checked',
                                    'checked');
                            }
                            if (res.catched == 0) {
                                $("#female").attr(
                                    'checked',
                                    'checked');
                            }
                            if (res.catched == 1) {
                                $("#feparamtype")
                                    .attr(
                                        'checked',
                                        'checked');
                            }
                            if (res.catched == 0) {
                                $("#paramtype")
                                    .attr(
                                        'checked',
                                        'checked');
                            }
                            editStart = 2;
                        }
                    });
                $("#EditContent").modal('show');

            });

//					$("#a_tab_list").click(function(){
//						getListser();
//						$("#tab_1_1_2").hide();
//						$("#tab_1_1_5").hide();
//						$("#tab_1_1_1").hide();
//						//$("#tab_1_1_4").show();
//					});

    // 保存数据
    $("#btn_save").click(function () {
        var validataResult = validateData();
        if (validataResult) {
            var editurl = "";
            if (editStart == 1) {
                editurl = postPath + '/system/server/insertServer';
            } else if (editStart == 2) {
                editurl = postPath + '/system/server/updateServering';
            }
            var ad = biaobiao;
            var serverdb = "";
            var timeDelay = $.trim($('#time_delay').val());
            if (editStart == 2) {
                serverdb = {
                    name: $("#name").val(),
                    dbKey: $("#dbkeys").val(),
                    sql: $("#sql").val().sqlreplaceAll(";", " "),
                    guid: $("#guid").val(),
                    remake: $("#remark").val(),
                    catchTime: $("#catchtime1").val(),
                    catched: $("input[name='catched']:checked").val(),
                    paramtype: $("input[name='paramtypes']:checked").val(),
                    timeDelay: 0
                    // timeDelay: isNaN(timeDelay) ? 0 : timeDelay
                };
            }
            if (editStart == 1) {
                serverdb = {
                    guid: $("#guid").val(),
                    name: $("#name").val(),
                    dbKey: ad,
                    sql: $("#sql").val().sqlreplaceAll(";", " "),
                    remake: $("#remark").val(),
                    catchTime: $("#catchtime1").val(),
                    catched: $("input[name='catched']:checked").val(),
                    paramtype: $("input[name='paramtypes']:checked").val(),
                    timeDelay: 0
                    // timeDelay: isNaN(timeDelay) ? 0 : timeDelay
                };
            }
            $.ajax({
                type: 'POST',
                url: editurl,
                async: false,
                data: JSON.stringify(serverdb),
                dataType: 'json',
                contentType: "application/json",
                success: function (res) {
                    showMsg("保存成功!", "success");
                    // bootbox.alert("保存成功!");
                    var zNodes = GetLeftTreeData();
                    $.fn.zTree.init($("#tree"), setting, zNodes);
                    $('#tb_dataList').bootstrapTable('refresh');
                    $("#EditContent").modal('hide');
                }
            });
        }

    });
    $("#btn_detailDel").click(function () {
        var row = $('#tb_fieldList').bootstrapTable('getSelections');
        if (row == null || row == "") {
            // bootbox.alert("请选择一行!");
            showMsg("请选择一行!", "warning");
            return;
        }
        bootbox.confirm("确认删除?", function (result) {
            if (result == false)
                return;
            var guid = "";
            $.each(row, function (i, e) {
                guid = e.guid;
            });
            $.ajax({
                url: postPath + '/system/server/deleteFiled',
                type: 'get',
                data: {
                    guid: guid
                },
                success: function (data) {
                    // bootbox.alert("删除成功!");
                    showMsg("删除成功!", "success");
                    $('#tb_fieldList').bootstrapTable('refresh');
                },
                error: function () {
                    // bootbox.alert("删除失败!");
                    showMsg("删除失败!", "error");
                }
            });
        });


    });

    // 删除节点数据
    $("#deletety")
        .click(
            function () {
                if (biaobiao == 0) {
                    // bootbox.alert("请选择要删除的节点!");
                    showMsg("请选择要删除的节点!", "warning");
                    return;
                }
                if (ppid == 0) {
                    // bootbox.alert("请选择要删除的服务名称!");
                    showMsg("请选择要删除的服务名称!", "warning");
                    return;
                }
                bootbox
                    .confirm(
                        "确认删除?",
                        function (result) {
                            if (result == false)
                                return;
                            $
                                .ajax({
                                    url: postPath
                                        + '/system/server/deleteServer',
                                    type: 'get',
                                    data: {
                                        keys: biaobiao
                                    },
                                    success: function (
                                        data) {
                                        // bootbox
                                        //     .alert("删除成功!");
                                        showMsg("删除成功!", "success");
                                        validateDataing();
                                        var zNodes = GetLeftTreeData();
                                        $.fn.zTree
                                            .init(
                                                $("#tree"),
                                                setting,
                                                zNodes);
                                        $(
                                            '#tb_dataList')
                                            .bootstrapTable(
                                                'refresh');
                                    },
                                    error: function () {
                                        // bootbox
                                        //     .alert("删除失败!");
                                        showMsg("删除失败!", "error");
                                    }
                                });
                        });
            });

    $("#editty").click(
        function () {
            cleanContent();
            if (ppid == 0) {
                // bootbox.alert("请选择子节点!");
                showMsg("请选择子节点!", "warning");
                return;
            }
            $.ajax({
                type: 'get',
                url: postPath
                    + '/system/server/seleServerOne',
                async: false,
                data: {
                    key: biaobiao
                },
                success: function (res) {
                    $("#guid").val(res.guid);
                    $("#name").val(res.name);
                    $("#dbkeys").val(res.dbKey);
                    $("#dbkeys").attr("readonly",
                        "readonly");
                    $("#sql").val(res.sql);
                    $("#remark").val(res.remake);
                    $("#catchtime1").val(res.catchTime);
                    if (res.catched == 1) {
                        $("#male").attr('checked',
                            'checked');
                    }
                    if (res.catched == 0) {
                        $("#female").attr('checked',
                            'checked');
                    }
                    if (res.paramtype == 1) {
                        $("#feparamtype").attr('checked',
                            'checked');
                    }
                    if (res.paramtype == 0) {
                        $("#paramtype").attr('checked',
                            'checked');
                    }
                    $("#serverids").hide();
                    editStart = 2;
                }
            });
            $("#EditContent").modal('show');
        });

    //返回列表
    $("#btn_back").click(function () {
        var projectId = $("#hid_projectid").val();
        var serverType = $("#hid_servertype").val();
        var seachTxt = (GetQueryStringSeachTxt("seachTxt"));
        window.location.href = postPath + "/prjService/index?order=asc&pageNo=1&pageSize=10&seachTxt=" + seachTxt + "&pcode=" + projectId + "&servertype=" + serverType;
    });

    function GetServerList() {
        if (ppid == 0) {
            return;
        }
        var xs = $("#serverId").val();
        $.ajax({
            type: 'get',
            url: postPath + '/system/server/selectServerOnes',
            async: false,
            data: {
                dbKey: xs
            },
            success: function (resd) {
                cleanServerInfo();
                var res = resd.data;
                if (res.dbServer.catched == 0) {
                }
                sts = res.dbServer.dbKey;
                // console.log("dbKey1" + res.dbServer.dbKey)
                x = res.dbServer.guid;

                var responseMode = resd.responseMode == null || resd.responseMode == '' ? 0 : resd.responseMode

                $("#catchtime").val(res.dbServer.catchTime);
                $("#serverId").val(res.dbServer.guid);
                $("#servicename").val(res.dbServer.name);
                $("#dbkey").val(res.dbServer.dbKey);
                $("#servertype").val(res.dbServer.paramtype);
                $("#remake").val(res.dbServer.remake);
                $("#sqlString").val(res.dbServer.sql);
                getCodesql(res.dbServer.sql);
                $("#sqlsts").val(res.dbServer.sql);
                $('select#servertype').val(res.dbServer.paramtype);
                $('#time_delay').val(res.dbServer.timeDelay);
                $(":radio[name='catcheds'][value='" + res.dbServer.catched + "']").prop("checked", "checked");
                $(":radio[name='ispags'][value='" + res.dbServer.isPaging + "']").prop("checked", "checked");
                $("input:radio[name='radioResponseMode'][value=" + responseMode + "]").attr("checked", true);
                $("#select").prop("disabled", true);
                $("#serverId").attr("readonly", "readonly");
                guid = res.dbServer.guid;
                $("#tab_1_1_5").hide();
                $("#tab_1_1_1").show();
                $("#tab_1_1_2").hide();
            }
        });
    }

    function GetServerListselect() {
        if (ppid == 0) {
            return;
        }
        var xs = $("#serverId").val();
        $.ajax({
            type: 'get',
            url: postPath + '/system/server/selectServerOnes',
            async: false,
            data: {
                dbKey: iso
            },
            success: function (resd) {
                var res = resd.data;
                if (res.dbServer.catched == 0) {
                }
                sts = res.dbServer.dbKey;
                // console.log("dbKey2 " + res.dbServer.dbKey)
                x = res.dbServer.guid;
                var responseMode = resd.responseMode == null || resd.responseMode == '' ? 0 : resd.responseMode == 'SingleMode' ? 1 : 0

                console.log("luowen 1")
                console.log(responseMode)
                console.log("luowen 2")
                console.log(resd)


                $("#catchtime").val(res.dbServer.catchTime);
                $("#serverId").val(res.dbServer.guid);
                $("#servicename").val(res.dbServer.name);
                $("#dbkey").val(sts);
                $("#servertype").val(res.dbServer.paramtype);
                $("#remake").val(res.dbServer.remake);
                $("#").val(res.dbServer.sql);
                getCodesql(res.dbServer.sql);
                $("#sqlsts").val(res.dbServer.sql);
                $('select#servertype').val(res.dbServer.paramtype);
                $('#time_delay').val(res.dbServer.timeDelay);
                if (res.dbServer.catched == 1) {
                    $("#catchtime").removeAttr("readonly");
                } else {
                    $("#catchtime").attr("readonly", "readonly");
                }
                $(":radio[name='catcheds'][value='" + res.dbServer.catched + "']").prop("checked", "checked");
                $(":radio[name='ispags'][value='" + res.dbServer.isPaging + "']").prop("checked", "checked");
                $("input:radio[name='radioResponseMode'][value=" + responseMode + "]").attr("checked", true);

                $("#select").prop("disabled", true);
                guid = res.dbServer.guid;
                $("#serverId").attr("readonly", "readonly");
                $("#tab_1_1_5").hide();
                $("#tab_1_1_1").show();
                $("#tab_1_1_2").hide();
            }
        });
    }

    $("#males").change(function () {
        $("#catchtime").removeAttr("readonly");
        $("#catchtime").val("");
    });
    $("#females").change(function () {
        $("#catchtime").attr("readonly", "readonly");
        $("#catchtime").val("");
    });
    $("#a_tab_column").click(function () {
        if (iso == "") {
            // bootbox.alert("请选择服务!");
            showMsg("请选择服务!", "warning");
            //getListser();
            $("#a_tab_field").attr("aria-expanded", false);
            $("#a_tab_list").attr("aria-expanded", true);
            $("#tab_1_1_2").hide();
            $("#tab_1_1_5").hide();
            $("#tab_1_1_1").show();
            $("#tab_1_1_3").hide();
            $("#tab_1_1_4").hide();
            //$("#tab_1_1_4").show();
            setTimeout(locationTab, 200);
            return;
        }

        locationcolumn();
        getFieldListing();
        $("#tab_1_1_5").hide();
        $("#tab_1_1_1").hide();
        $("#tab_1_1_2").hide();
        $("#tab_1_1_3").show();
        $("#tab_1_1_4").hide();
    });

    // $("#a_tab_f").click(function () {
    //     $("#tab_1_1_1").hide();
    //     $("#tab_1_1_2").hide();
    //     $("#tab_1_1_3").hide();
    //     $("#tab_1_1_4").show();
    // });



    $("#a_tab_f").click(function () {
        if (iso == "") {
            // bootbox.alert("请选择服务!");
            showMsg("请选择服务!", "warning");
            //getListser();
            $("#a_tab_field").attr("aria-expanded", false);
            $("#a_tab_list").attr("aria-expanded", true);
            $("#tab_1_1_2").hide();
            $("#tab_1_1_5").hide();
            $("#tab_1_1_1").show();
            $("#tab_1_1_3").hide();
            $("#tab_1_1_4").hide();

            //$("#tab_1_1_4").show();
            setTimeout(locationTab, 200);
            return;
        }
        $("#tablenames").empty();
        getFieldList();
        $("#tablename").empty();
        sts = $("#dbkey option:selected").val();
        $.ajax({
            type: 'get',
            url: postPath
                + '/system/server/selectTableMap',
            async: false,
            data: {
                dbKey: sts
            },
            success: function (res) {
                var ad = "请选择数据库里面的表";
                $("#tablenames").append(
                    "<option value=>" + ad
                    + "</option>");
                $.each(res, function (i, e) {
                    $("#tablenames").append(
                        "<option value=" + i + ">"
                        + e + "</option>");
                });
            }
        });
        $("#tab_1_1_2").hide();
        $("#tab_1_1_5").hide();
        $("#tab_1_1_1").hide();
        $("#tab_1_1_3").hide();
        $("#tab_1_1_4").show();
        app.getNewData(2);
        //$("#tab_1_1_4").hide();
    });



    $("#a_tab_field").click(function () {
        if (iso == "") {
            // bootbox.alert("请选择服务!");
            showMsg("请选择服务!", "warning");
            //getListser();
            $("#a_tab_field").attr("aria-expanded", false);
            $("#a_tab_list").attr("aria-expanded", true);
            $("#tab_1_1_2").hide();
            $("#tab_1_1_5").hide();
            $("#tab_1_1_1").show();
            $("#tab_1_1_3").hide();
            $("#tab_1_1_4").hide();
            //$("#tab_1_1_4").show();
            setTimeout(locationTab, 200);
            return;
        }
        $("#tablenames").empty();
        getFieldList();
        $("#tablename").empty();
        sts = $("#dbkey option:selected").val();
        $.ajax({
            type: 'get',
            url: postPath
                + '/system/server/selectTableMap',
            async: false,
            data: {
                dbKey: sts
            },
            success: function (res) {
                var ad = "请选择数据库里面的表";
                $("#tablenames").append(
                    "<option value=>" + ad
                    + "</option>");
                $.each(res, function (i, e) {
                    $("#tablenames").append(
                        "<option value=" + i + ">"
                        + e + "</option>");
                });
            }
        });
        $("#tab_1_1_2").show();
        $("#tab_1_1_5").show();
        $("#tab_1_1_1").hide();
        $("#tab_1_1_3").hide();
        $("#tab_1_1_4").hide();
        //$("#tab_1_1_4").hide();
    });

    function addcolumn() {
        return add;
    }

    function ascoumns() {
        getFieldList();
        $("#tablename").empty();
        if (ppid == 10000) {
            sts = biaobiao;
        } else {
            sts = ppid;
        }
        $.ajax({
            type: 'get',
            url: postPath + '/system/server/selectTableMap',
            async: false,
            data: {
                dbKey: sts
            },
            success: function (res) {
                var ad = "请选择数据库里面的表";
                $("#tablename").append(
                    "<option value=>" + ad + "</option>");
                $.each(res, function (i, e) {
                    $("#tablenames").append(
                        "<option value=" + i + ">" + e
                        + "</option>");
                });
            }
        });
        $("#tab_1_1_5").show();
        $("#tab_1_1_1").hide();
    }

    // 下拉框点击事件
    $("#btn_fieldAdds").click(function () {
        getFieldLists();

    });

    $("#a_tab_table").click(function () {
        $("#valide_dtMessage").html("");
        attrs = 2;
        $("#serverId").attr("readonly", false);
        //$("#dbKey").val(biaobiao);
        //getFieldList();
        $("#tab_1_1_2").hide();
        $("#tab_1_1_5").hide();
        $("#tab_1_1_1").show();
        $("#tab_1_1_3").hide();
        $("#tab_1_1_4").hide();
        GetServerList();
    });

    function showTableName() {
//						$.ajax({
//							type : 'get',
//							url : postPath + '/system/server/selectTableName',
//							async : false,
//							data : {
//								dbKey : biaobiao
//							},
//							success : function(res) {
//								$.each(res.data, function(i, e) {
//									$("#tablename").append(
//											"<option value=" + i + ">" + e
//													+ "</option>");
//								});
//							}
//						});
    }

    function getDBType() {
        var dbtype = $("#dbkey option:selected").val();
        var issqlserver = true;
        $.ajax({
            type: 'get',
            url: postPath + '/system/server/selectDBType',
            async: false,
            data: {
                dbkey: dbtype
            },
            success: function (res) {
                issqlserver = res;
            }
        });
        return issqlserver;
    }

    function getField() {
        // console.log("getField")
        var xstring = $("#serverId").val();// $("#servicename").val();
        var sqls = encryptByDES(myCodeMirror.getValue().sqlreplaceAll(";", " "), "12345678");
        var dbkeys = $("#dbkey option:selected").val();
        var msg = '';
        // console.log("加密前："+myCodeMirror.getValue().sqlreplaceAll(";", " "));
        // console.log("加密后："+sqls);
        $.ajax({
            type: 'POST',
            url: postPath + '/system/server/selectServerColumnExit',
            async: false,
            data: {
                sysId: xstring,
                sql: sqls,
                dbkey: dbkeys
            },
            success: function (res) {
                msg = res
            }
        });
        return msg;
    }

    // 展示信息
    function getFieldList() {
        $("#tb_fieldLists")
            .bootstrapTable('destroy')
            .bootstrapTable(
                {
                    url: postPath
                        + '/system/server/selectServerColumn',
                    undefinedText: '-',
                    striped: true, // 是否显示行间隔色
                    queryParams: queryFieldParams,
                    cache: false, // 是否使用缓存
                    uniqueId: "guid", // 每一行的唯一标识
                    columns: [{
                        title: '字段名称',
                        field: 'filedname',
                        align: 'center',
                        valign: 'middle'
                    }, {
                        title: '中文名称',
                        field: 'fieldcaption',
                        align: 'center',
                        valign: 'middle',
                        editable: {
                            type: 'text',
                            title: '中文名称',
                            validate: function (v) {

                            }
                        }
                    }, {
                        title: '显示顺序',
                        field: 'showorder',
                        align: 'center',
                        valign: 'middle',
                        editable: {
                            type: 'text',
                            title: '显示顺序',
                            validate: function (v) {

                            }
                        }
                    },
//											{
//												title : '显示类型',
//												field : 'showtype',
//												align : 'center',
//												valign : 'middle',
//												editable : {
//													type : 'select',
//													title : '显示类型',
//													source : [{
//														value : "1",
//														text : "日期框"
//													}, {
//														value : "2",
//														text : "文本框"
//													}, {
//														value : "3",
//														text : "下拉框"
//													}, {
//														value : "4",
//														text : "数值框"
//													}, {
//														value : "5",
//														text : "复选框"
//													}, {
//														value : "6",
//														text : "单选按钮"
//													} ]
//												}
//											},
                        {
                            title: '是否是排序字段',
                            field: 'isqueryfield',
                            align: 'center',
                            valign: 'middle',
                            editable: {
                                type: 'select',
                                title: '是否是排序字段',
                                source: [{
                                    value: "1",
                                    text: "是"
                                }, {
                                    value: "0",
                                    text: "否"
                                },
                                ]
                            }
                        }, {
                            title: '如何排序',
                            field: 'queryorder',
                            align: 'center',
                            valign: 'middle',
                            editable: {
                                type: 'select',
                                title: '如何排序',
                                source: [{
                                    value: "1",
                                    text: "正序"
                                }, {
                                    value: "0",
                                    text: "倒序"
                                }]
                            }
                        }, {
                            title: '配置表ID',
                            field: 'dtConfigId',
                            align: 'center',
                            valign: 'middle',
                        }]

                });
    }

    function getFieldListing() {
        $("#tb_fieldList")
            .bootstrapTable('destroy')
            .bootstrapTable(
                {
                    url: postPath + '/system/server/selectAllFiled',
                    undefinedText: '-',
                    striped: true, // 是否显示行间隔色
                    queryParams: queryFieldParaming,
                    cache: false, // 是否使用缓存
                    uniqueId: "guid", // 每一行的唯一标识
                    columns: [{
                        title: '参数Code',
                        field: 'parametercode',
                        align: 'center',
                        valign: 'middle',
                        editable: {
                            type: 'text',
                            title: '参数Code',
                            validate: function (v) {

                            }
                        }
                    }, {
                        title: '参数对应的Java类型',
                        field: 'fieldJavaType',
                        align: 'center',
                        valign: 'middle',
                        editable: {
                            type: 'select',
                            title: 'Java类型',
                            source: [{
                                value: "Byte",
                                text: "Byte"
                            },{
                                value: "String",
                                text: "String"
                            },{
                                value: "BigDecimal",
                                text: "BigDecimal"
                            },{
                                value: "Short",
                                text: "Short"
                            },{
                                value: "Integer",
                                text: "Integer"
                            },{
                                value: "Long",
                                text: "Long"
                            },{
                                value: "Float",
                                text: "Float"
                            },{
                                value: "Double",
                                text: "Double"
                            },{
                                value: "byte[]",
                                text: "byte[]"
                            },{
                                value: "Date",
                                text: "Date"
                            },{
                                value: "Time",
                                text: "Time"
                            },{
                                value: "Timestamp",
                                text: "Timestamp"
                            },{
                                value: "Boolean",
                                text: "Boolean"
                            }]
                        }
                    },{
                        title: '中文名称',
                        field: 'note',
                        align: 'center',
                        valign: 'middle',
                        editable: {
                            type: 'text',
                            title: '中文名称',
                            validate: function (v) {
                            }
                        }
                    }
                    ]

                });
    }

    // 展示信息
    function getFieldLists() {
        $("#tb_fieldLists")
            .bootstrapTable('destroy')
            .bootstrapTable(
                {
                    url: postPath
                        + '/system/server/selectServerShintColumn',
                    undefinedText: '-',
                    striped: true, // 是否显示行间隔色
                    queryParams: queryFieldParames,
                    toolbar: "",// 指定工具栏
                    uniqueId: "guid", // 每一行的唯一标识
                    columns: [{
                        field: 'state',
                        checkbox: true,
                        align: 'center',
                        valign: 'middle'
                    }, {
                        title: '字段名称',
                        field: 'filedname',
                        align: 'center',
                        valign: 'middle'
                    }, {
                        title: '中文名称',
                        field: 'fieldcaption',
                        align: 'center',
                        valign: 'middle',
                        editable: {
                            type: 'text',
                            title: '中文名称',
                            validate: function (v) {

                            }
                        }
                    }, {
                        title: '显示顺序',
                        field: 'showorder',
                        align: 'center',
                        valign: 'middle',
                        editable: {
                            type: 'text',
                            title: '显示顺序',
                            validate: function (v) {

                            }
                        }
                    },
//											{
//												title : '显示类型',
//												field : 'showtype',
//												align : 'center',
//												valign : 'middle',
//												editable : {
//													type : 'select',
//													title : '显示类型',
//													source : [{
//														value : "1",
//														text : "日期框"
//													}, {
//														value : "2",
//														text : "文本框"
//													}, {
//														value : "3",
//														text : "下拉框"
//													}, {
//														value : "4",
//														text : "数值框"
//													}, {
//														value : "5",
//														text : "复选框"
//													}, {
//														value : "6",
//														text : "单选按钮"
//													} ]
//												}
//											},
                        {
                            title: '是否是排序字段',
                            field: 'isqueryfield',
                            align: 'center',
                            valign: 'middle',
                            editable: {
                                type: 'select',
                                title: '是否是排序字段',
                                source: [{
                                    value: "1",
                                    text: "是"
                                }, {
                                    value: "0",
                                    text: "否"
                                }]
                            }
                        }, {
                            title: '如何排序',
                            field: 'queryorder',
                            align: 'center',
                            valign: 'middle',
                            editable: {
                                type: 'select',
                                title: '如何排序',
                                source: [{
                                    value: "1",
                                    text: "正序"
                                }, {
                                    value: "0",
                                    text: "倒序"
                                }]
                            }
                        }, {
                            title: '配置表ID',
                            title: '配置表ID',
                            field: 'dtConfigId',
                            align: 'center',
                            valign: 'middle',
                        }]

                });
    }

    // funciton getAllDatatableData(oTableLocal){
    // var aReturn =new Array();
    // var aTrs = oTableLocal.fnGetNodes();
    // for(var i=0; i<aTrs.length;i++){
    // aReturn.push(oTableLocal.fnGetData(aTrs[i]));
    // }
    // return aReturn;
    // }

    $("#btn_serverEdit").click(function () {
        $('#btn_serverEdit').show();
        $('input').attr("readonly", false);
        $("#servertype").attr("readonly", false);
        $("input:radio").attr("disabled", false);
        $("#sqlString").attr("readonly", false);
    });

    $("#btn_fieldSave")
        .click(
            function () {
                var allTableData = $("#tb_fieldLists")
                    .bootstrapTable('getData');
                console.log("luowen allTableData", allTableData);
                var exiturl = postPath
                    + '/system/server/saveBaseSqlConfig';
                $.ajax({
                    type: 'POST',
                    url: exiturl,
                    async: false,
                    data: JSON
                        .stringify(allTableData),
                    dataType: 'json',
                    contentType: 'application/json;charset=UTF-8',
                    success: function (res) {
                        // bootbox.alert("保存成功!");
                        showMsg("保存成功!", "success");
                        ascoumns();
                    }
                });
            });

    function queryFieldParams(pageReqeust) {
        var temp = {
            order: pageReqeust.order,
            sysId: iso
        };
        return temp;
    }

    function queryFieldParaming(pageReqeust) {
        var sid = $("#serverId").val();
        var temp = {
            order: pageReqeust.order,
            sysId: sid
        };
        return temp;
    }

    $("#btn_detailEndit")
        .click(
            function () {
                var allTableData = $("#tb_fieldList").bootstrapTable('getData');
                var exiturl = postPath + '/system/server/saveFiledConfig';
                console.log("luowen ", allTableData)
                $.ajax({
                    type: 'POST',
                    url: exiturl,
                    async: false,
                    data: JSON.stringify(allTableData),
                    dataType: 'json',
                    contentType: 'application/json;charset=UTF-8',
                    success: function (res) {
                        // bootbox.alert("保存成功!");
                        showMsg("保存成功!", "success");
                        //ascoumns();
                    }
                });
            });

    $("#btn_autoManageFieldType")
        .click(
            function () {
                var allTableData = $("#tb_fieldList").bootstrapTable('getData');
                var exiturl = postPath + '/system/server/autoManageFieldType';
                $.ajax({
                    type: 'POST',
                    url: exiturl,
                    async: false,
                    data: JSON.stringify(allTableData),
                    dataType: 'json',
                    contentType: 'application/json;charset=UTF-8',
                    success: function (res) {
                        // bootbox.alert("保存成功!");
                        $('#tb_fieldList').bootstrapTable('refresh');

                        //ascoumns();
                    }
                });
            });

    $("#btn_columnsave").click(function () {
        if (validateColumn()) {
            var url = postPath + '/system/server/insertField';
            var serverdb = {
                parametercode: $("#column").val(),
                parametervalue: $("#columnname").val(),
                showtype: $("#parametertype").val(),
                remark: $("#parameterformat").val(),
                serviceid: iso,
                servicetype: 4,
            };

            $.ajax({
                type: 'POST',
                url: url,
                async: false,
                data: JSON.stringify(serverdb),
                dataType: 'text',
                contentType: "application/json",
                success: function (res) {
                    // bootbox.alert("保存成功!");
                    showMsg("保存成功!", "success");
                    locationcolumn();
                    getFieldListing();
                    $("#tab_1_1_5").hide();
                    $("#tab_1_1_1").hide();
                    $("#tab_1_1_2").hide();
                    $("#tab_1_1_3").show();
                    $('#a_fieldconfig_2_2').click();
                }
            });

        }
    });

    function btn_columnsave() {
        var validataResult = validateColumn();
        var editurl = "";
        if (validataResult) {
            editurl = postPath + '/system/server/insertField';
        }
        var serverdb = {
            parametercode: $("#column").val(),
            parametervalue: $("#columnname").val(),
            showtype: $("#parametertype").val(),
            remark: $("#parameterformat").val(),
            serviceid: dbk,
            servicetype: 4,
        };
        $.ajax({
            type: 'POST',
            url: editurl,
            async: false,
            data: JSON.stringify(serverdb),
            dataType: 'json',
            contentType: "application/json",
            success: function (res) {
                // bootbox.alert("保存成功!");
                showMsg("保存成功!", "success");
            }
        });
    }

    $("#btn_serverSavess")
        .click(
            function () {
                var editurl = postPath
                    + '/system/server/updateServering';
                var timeDelay = $.trim($('#time_delay').val());
                var serverdb = {
                    "guid": guid,
                    "name": $("#servicename").val(),
                    "paramtype": $("#servertype")
                        .val(),
                    "sql": $("#sqlString").val().sqlreplaceAll(";", " "),
                    "remake": $("#remake").val(),
                    "catched": $(
                        "input[name='catched']:checked")
                        .val(),
                    "isPaging": $(
                        "input[name='ispag']:checked")
                        .val(),
                    "timeDelay": isNaN(timeDelay) ? 0 : timeDelay,
                    "responseMode" : $('input:radio[name="radioResponseMode"]:checked').val()
                };

                $
                    .ajax({
                        type: 'POST',
                        url: editurl,
                        async: false,
                        data: JSON
                            .stringify(serverdb),
                        dataType: 'json',
                        contentType: 'application/json;charset=UTF-8',
                        success: function (res) {
                            // bootbox.alert("保存成功!");
                            showMsg("保存成功!", "success");
                            var zNodes = GetLeftTreeData();
                            $.fn.zTree
                                .init(
                                    $("#tree"),
                                    setting,
                                    zNodes);
                            $("#censusTree").modal(
                                'hide');
                        }
                    });
            });
    //页面保存功能
    $("#btn_serverSave").click(function () {
        var validataResult = validateDatass();
        if (validataResult) {
            var editurl = "";
            if (attrs == 1) {
                editurl = postPath + '/system/server/insertServer';
            } else if (attrs == 2) {
                editurl = postPath + '/system/server/updateServering';
            }
            var sad = "";
            if (ppid == 0) {
                sad = dbk;
            } else {
                sad = ppid;
            }
            var ad = biaobiao;
            var serverdb = "";
            var timeDelay = $.trim($('#time_delay').val());
            var sql = myCodeMirror.getValue().sqlreplaceAll(";", "");
            // console.log("sql:"+sql)
            // .sqlreplaceAll(" +","-");
            //使用des加密，密钥12345678
            var sqldes = encryptByDES(sql, "12345678");
            // console.log("sqldes:" + sqldes)
            // var sqlbase64 = encode(sql)
            if (attrs == 1) {
                serverdb = {
                    name: $("#servicename").val(),
                    dbKey: $("#dbkey option:selected").val(),
                    sql: sqldes,
                    guid: $("#serverId").val(),
                    remake: $("#remake").val(),
                    catchTime: $("#catchtime").val(),
                    catched: $("input[name='catcheds']:checked").val(),
                    isPaging: $("input[name='ispags']:checked").val(),
                    hidServertype: $("#hid_servertype").val(),
                    hidProjectid: $("#hid_projectid").val(),
                    // timeDelay: isNaN(timeDelay) ? 0 : timeDelay
                    timeDelay: 0,
                    responseMode: $('input:radio[name="radioResponseMode"]:checked').val()
                };
            }
            if (attrs == 2) {
                serverdb = {
                    name: $("#servicename").val(),
                    dbKey: $("#dbkey option:selected").val(),
                    sql: sqldes,
                    guid: $("#serverId").val(),
                    remake: $("#remake").val(),
                    catchTime: $("#catchtime").val(),
                    catched: $("input[name='catcheds']:checked").val(),
                    isPaging: $("input[name='ispags']:checked").val(),
                    timeDelay: 0,
                    // timeDelay: isNaN(timeDelay) ? 0 : timeDelay
                    responseMode: $('input:radio[name="radioResponseMode"]:checked').val()
                };
            }

            $.ajax({
                type: 'POST',
                url: editurl,
                async: false,
                data: JSON.stringify(serverdb),
                dataType: 'json',
                contentType: "application/json",
                success: function (res) {
                    $("#serverId").attr("readonly", "readonly");
                    // bootbox.alert("保存成功!");
                    showMsg("保存成功!", "success");
                    var zNodes = GetLeftTreeData();
                    // getFieldList();
                    $.fn.zTree.init($("#tree"), setting, zNodes);
                    $('#tree').bootstrapTable('refresh');
                    $("#EditContent").modal('hide');
                    //getFieldList();
                    iso = $("#serverId").val();
                    $("#sqlsts").val(myCodeMirror.getValue().sqlreplaceAll(";", " "));
                    attrs = 2;
                }
            });
        }

    });

    function queryFieldParames(pageReqeust) {
        var checkValue = $("#tablenames").val();
        var temp = {
            order: pageReqeust.order,
            key: checkValue,
            dbKey: iso
        };
        console.log("luowen temp", temp);
        return temp;
    }

    // 获取左侧列表数据
    function GetLeftTreeData() {
        var treeData;
        $.ajax({
            type: 'get',
            url: postPath + '/system/server/treeList',
            async: false,
            success: function (res) {
                treeData = res.data;
            },
            error: function () {
                alert('error...');
            }
        });
        return treeData;
    }

    // 表单验证
    function validTableInfo() {
        if ($("#servicename").val() == "") {
            $("#valide_dtMessage").html("请输入服务名称");
            return false;
        } else {
            $("#valide_dtMessage").html("");
        }
        if ($("#dbKey  option:selected").val() == "") {
            $("#valide_dtMessage").html("请选择数据库名称");
            return false;
        } else {
            $("#valide_dtMessage").html("");
        }
        if ($("#servertype").val() == "") {
            $("#valide_dtMessage").html("请输入参数类型");
            return false;
        } else {
            $("#valide_dtMessage").html("");
        }
        if ($("#remake").val() == "") {
            $("#valide_dtMessage").html("请填写备注");
            return false;
        } else {
            $("#valide_dtMessage").html("");
        }
        if (myCodeMirror.getValue().sqlreplaceAll(";", " ") == "") {
            $("#valide_dtMessage").html("请输入sql脚本");
            return false;
        } else {
            $("#valide_dtMessage").html("");
        }
        return true;
    }

    // 添加内容请空
    function cleanContent() {
        // 维护内容清空
        $("#guid").val("");
        $("#guid").removeAttr("readonly");
        $("#name").val("");
        $("#dbkey").val("");
        $("#sql").val("");
        $("#remark").val("");
        $("#catchtime1").val("");

        // 验证信息清空
        $("#valide_guid").html("");
        $("#valide_name").html("");
        $("#valide_dbkey").html("");
        $("#valide_sql").html("");
        $("#valide_remark").html("");
        $("#valide_catchtime1").html("");
    }

    // 验证表单内容
    function validateData() {
        if ($("#guid").val() == "") {
            $("#valide_guid").html("服务ID不能为空!");
            return false;
        } else {
            $("#valide_guid").html("");
        }
        if ($("#name").val() == "") {
            $("#valide_name").html("服务名称不能为空!");
            return false;
        } else {
            $("#valide_name").html("");
        }
        if ($("#sql").val() == "") {
            $("#valide_sql").html("sql脚本不能为空!");
            return false;
        } else {
            $("#valide_sql").html("");
        }
        return true;
    }

    //清空显示页
    function validateDatass() {
        if ($("#dbkey option:selected").val() == "") {
            $("#valide_dtMessage").html("请选择数据库!");
            return false;
        } else {
            $("#valide_dtMessage").html("");
        }
        if ($("#serverId").val() == "") {
            $("#valide_dtMessage").html("服务ID不能为空!");
            return false;
        } else {
            $("#valide_dtMessage").html("");
        }
        if ($("#servicename").val() == "") {
            $("#valide_dtMessage").html("服务名称不能为空!");
            return false;
        } else {
            $("#valide_dtMessage").html("");
        }
        if ($("input[name='catcheds']:checked").val() == 1) {
            if ($("#catchtime").val() == "") {
                $("#valide_dtMessage").html("缓存时间不能为空!");
                return false;
            } else {
                var re = /^[1-9]+[0-9]*]*$/; //判断字符串是否为数字
                if (!re.test($("#catchtime").val())) {
                    $("#valide_dtMessage").html("缓存时间为正整数!");
                    return false;
                }
                $("#valide_dtMessage").html("");
            }
        }
        //alert(myCodeMirror.getValue());
        if (myCodeMirror.getValue().sqlreplaceAll(";", " ") == "") {
            $("#valide_dtMessage").html("sql脚本不能为空!");
            return false;
        } else {
            $("#valide_dtMessage").html("");
        }
        // if(myCodeMirror.getValue() != ""){
        // 	//var xxcc = myCodeMirror.getValue().toLowerCase().indexOf("order by");
        // 	//alert(myCodeMirror.getValue().toLowerCase().indexOf("order by")!=-1);
        // 	if(getDBType()&&myCodeMirror.getValue().toLowerCase().indexOf("order by")!=-1){
        // 		$("#valide_dtMessage").html("sql脚本中不允许含有排序!");
        // 		return false;
        // 	}else{
        // 		$("#valide_dtMessage").html("");
        // 	}
        // }
        if (myCodeMirror.getValue().sqlreplaceAll(";", " ") != "") {
            var result = getField();
            if (result.success) {
                $("#valide_dtMessage").html("");
            } else {
                $("#valide_dtMessage").html(result.msg !== '' ? result.msg : "sql脚本语法错误!");
                return false;
            }
        }
        var re = 0;
        if (attrs == 1) {
            var selectguid = $("#serverId").val();
            $.ajax({
                type: 'get',
                url: postPath + '/system/treeConfig/selectCountGUID',
                async: false,
                data: {
                    dbKey: selectguid
                },
                success: function (res) {
                    re = res;
                }
            });
        }
        if (re != 0) {
            $("#valide_dtMessage").html("该服务ID在表中已存在");
            return false;
        } else {
            $("#valide_dtMessage").html("");
        }
        return true;
    }

    //清空展示页面
    function validateDataing() {
        $("#serverId").val("");
        $("#servicename").val("");
        $("dbKey").val("");
        $("#remake").val("");
        $("#catchtime").val("");
        etCodesql("");

        $("#valide_dtMessage").html("");
    }


});

//临时所加代码
//获取详情
function getListser() {
    $(".tree-2 tbody").html("");
    var stss = $("#seachTxt").val();
    $.ajax({
        type: 'get',
        url: postPath + '/system/server/getExtSqlList',
        async: false,
        data: {
            dbkey: dbk,
            searchkey: stss
        },
        dataType: 'json',
        contentType: "application/json",
        success: function (res) {
            var strtd = "";
            $.each(res, function (i, e) {
                var aa = e.guid;
                strtd += "<tr class='treegrid-" + e.guid + "'>";
                strtd += "<td>" + (e.servicename == null ? "" : e.servicename) + "</td><td>" + (e.dtDbKey == null ? "" : e.dtDbKey) + "</td><td>" + (e.ispagination == null ? "" : e.ispagination) + "</td><td>" + (e.syscatch == null ? "" : e.syscatch) + "</td><td>" + (e.catchtime == null ? "" : e.catchtime) + "</td><td>" + (e.dtSql == null ? "" : e.dtSql) + "</td>";
                strtd += "<td>";
                strtd += "<a href='javascript:;' onclick='updateClick(\"" + aa + "\");' class='btn btn-default btn-sm'><i class='fa fa-edit'></i> </a> ";
                strtd += " <a href='javascript:;' onclick='delClick(\"" + aa + "\");' class='btn btn-default btn-sm'><i class='fa fa-remove'></i> ";
                strtd += " </a></td></tr>";
            });
            $(".tree-2 tbody").append(strtd);
        }
    });
}

function delClick(xx) {
    bootbox.confirm("确认删除?", function (result) {
        if (result == false)
            return;
        $.ajax({
            url: postPath + '/system/server/deleteServer',
            type: 'get',
            data: {
                keys: xx
            },
            success: function (data) {
                // bootbox.alert("删除成功!");
                showMsg("删除成功!", "success");
                $('#tb_dataList').bootstrapTable('refresh');
                getListser();
            },
            error: function () {
                // bootbox.alert("删除失败!");
                showMsg("删除失败!", "error");
            }
        });
    });
}

function updateClick(xx) {
    cleanServerInfo();
    $("#serverId").attr("readonly", "readonly");
    biaobiao = xx;
    ppid = dbk;
    attrs = 2;
    GetServerLists(xx);
    locationTabing();
}

function GetServerLists(xx) {
    $.ajax({
        type: 'get',
        url: postPath + '/system/server/selectServerOnes',
        async: false,
        data: {
            dbKey: xx
        },
        success: function (resd) {
            var res = resd.data;
            // console.log("dbKey3" + res.dbServer.dbKey)
            if (res.dbServer.catched == 0) {
            }
            $("#catchtime").val(res.dbServer.catchTime);
            $("#serverId").val(res.dbServer.guid);
            $("#servicename").val(res.dbServer.name);
            //$("#dbKey").val();
            $('select#dbKey').val(res.dbServer.dbKey);
            $("#servertype").val(res.dbServer.paramtype);
            $("#remake").val(res.dbServer.remake);
            $("#sqlString").val(res.dbServer.sql);
            getCodesql(res.dbServer.sql);
            $('select#servertype').val(
                res.dbServer.paramtype);
            $(
                ":radio[name='catcheds'][value='"
                + res.dbServer.catched + "']")
                .prop("checked", "checked");
            $(
                ":radio[name='ispags'][value='"
                + res.dbServer.isPaging + "']")
                .prop("checked", "checked");

            $("#select").prop("disabled", true);
            guid = res.dbServer.guid;
            $("#tab_1_1_5").hide();
            $("#tab_1_1_1").show();
            $("#tab_1_1_2").hide();
            //$("#tab_1_1_4").hide();
        }
    });
}

function locationTabing() {
    $('#myTab a[href="#tab_1_1_1"]').tab('show');
}

//表信息配置-清空信息
function cleanServerInfo() {
    $("#serverId").val("");
    $("#servicename").val("");
    $("#dbKey").empty();
    $("#servertype").val("");
    $("#remake").val("");
    $("#sqlString").val("");
    getCodesql("");
    $("#catchtime").val("");
}


function cleanColumn() {
    $("#column").val("");
    $("#columnname").val("");
    $("#parameterformat").val("");
}


//清空显示页
function validateColumn() {
    if ($("#column").val() == "") {
        $("#derrorInfo").html("字段Code不能为空!");
        return false;
    } else {
        $("#derrorInfo").html("");
    }
    if ($("#parametertype").val() == 5) {
        $("#derrorInfo").html("参数类型不能为空!");
        return false;
    } else {
        $("#derrorInfo").html("");
    }
    /*if ($("#parameterformat").val() == "") {
        $("#derrorInfo").html("参数格式不能为空!");
        return false;
    } else {
        $("#derrorInfo").html("");
    }*/

    return true;
}

function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

function GetQueryStringSeachTxt(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return r[2];
    return null;
}

//Code编辑器
var myTextArea = document.getElementById('code_editor');
var myCodeMirror = CodeMirror.fromTextArea(myTextArea, {
    lineNumbers: true,
    matchBrackets: true,
    styleActiveLine: true,
    lineWrapping: true,
    height: '100px',
    theme: "neat",
    mode: 'text/x-mariadb'
});

//Code编辑器
var myTextAreaColumn = document.getElementById('code_editorColumn');
var myCodeMirrorColumn = CodeMirror.fromTextArea(myTextAreaColumn, {
    lineNumbers: false,
    matchBrackets: true,
    styleActiveLine: false,
    lineWrapping: true,
    height: '100px',
    theme: "neat",
    mode: 'text/x-mariadb',
    readOnly: true
});

//sql文初始化
function getCodesql(result) {
    myCodeMirror.setValue(result);
    myCodeMirrorColumn.setValue(result);
}

//增加sql字符串替换函数sqlreplaceAll
String.prototype.sqlreplaceAll = function (s1, s2) {
    return this.replace(new RegExp(s1, "gm"), s2);
}

//字符串转base64
function encode(str) {
// 对字符串进行编码
    var encode = encodeURI(str);
// 对编码的字符串转化base64
    var base64 = btoa(encode);
    return base64;
}

function encryptByDES(message, key) {
    // console.log("encryptByDES")
    var keyHex = CryptoJS.enc.Utf8.parse(key);
    var encrypted = CryptoJS.DES.encrypt(message, keyHex, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    });
    // console.log("encryptByDES 成功")
    return encrypted.toString();
}

function showMsg(text, icon) {
    $.toast().reset('all');
    $.toast({
        text: text,
        icon: icon,
        showHideTransition: 'fade',
        allowToastClose: true,
        hideAfter: 1500,
        stack: false,
        position: 'top-right',
        textAlign: 'left',
        loader: true,
        loaderBg: '#9ec600',
    });
}
